// $.get("header_menu.html",function(data){ $("#header").html(data); });
$.get("footer.html",function(data){ $("#footer").html(data); });

$(document).ready(function() {
    // $("#feedback").addClass("active");
    // $("#feedback1").addClass("active");

    getData1(1);

    function pageDivd(curr, page_num) {
        layui.use(['laypage', 'layer'], function () {
            var laypage = layui.laypage
                , layer = layui.layer;
            laypage.render({
                elem: 'demo7',
                count: page_num,
                limit: 5,
                curr: curr,
                jump: function (obj, first) {
                    if (!first) {
                        getData1(obj.curr);
                    }
                }
            });
        })
    }

    function getData1(curr) {
        $.ajax({
            type: "get",
            url: "http://114.116.72.220:9999/ShowOpinion",
            async: true,
            data: {
                page: curr,
                row: 5,
                keyword: $('#input1').val()
            },
            success: function (data) {
                if (data[0].length == 0) {
                    layer.msg('暂无数据');
                }
                TableView(data[0]);
                pageDivd(curr, data[1]);
            }
        });
    }

    function TableView(data) {
        $('#group_table').html('');

        for (var i = 0; i < data.length; i++) {
            var trText = `<tr num="${data[i].opinion_id}" class="${i % 2 ? '' : 'tr_back'}">
		      		    
		      		    		<td>${i + 1}</td>
		      		    		<!--<td>${data[i].name}</td>-->
		      		    		<td>
		      		    			${data[i].phone}
		      		    		</td>
		      		    		<td>
		      		    			${data[i].opinion}
		      		    		</td>
		      		    		<td>
		      		    			${data[i].time}
		      		    		</td>
		      		    		<td>
		      		    			<button class="btn_do">未处理</button>
		      		    		</td>
                        </tr>
		      		    	`;

            $('#group_table').append(trText);

        }

        $('.btn_do').click(function () {
            var Index = $(this).parent().parent().attr('num');
            $.ajax({
                type: "get",
                url: "http://114.116.72.220:9999/DealOpinion",
                async: true,
                data: {
                    opinionId: Index
                },
                success: function (data) {
                    if (data == 'success') {
                        layer.msg('处理成功', {time: 500}, function () {
                            location.reload();
                        })
                    } else {
                        layer.msg('处理失败')
                    }

                }

            })
        })

    }

    $(".check1").click(function () {
        getData1(1);
    });

});